package cn.t.web.ent;

import cn.t.core.mode.PageInfoDTO;
import cn.t.core.mode.PageQueryDTO;
import cn.t.dto.user.CostCenterDTO;
import cn.t.facade.user.CostCenterFacade;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 企业站-智能柜成本中心管理
 */
@Slf4j
@RestController
@RequestMapping("/ent/costCenter")
@AllArgsConstructor
public class EntCostCenterController {

    private final CostCenterFacade costCenterFacade;

    /**
     * 成本中心分页查询
     */
    @PostMapping("/page")
    public PageInfoDTO<CostCenterDTO> entCostCenterPage(@RequestBody PageQueryDTO<CostCenterDTO> queryDTO) {
        return this.costCenterFacade.entCostCenterPage(queryDTO);
    }

    /**
     * 新建成本中心
     */
    @PostMapping("save")
    public Boolean save(@Valid @RequestBody CostCenterDTO dto) {
        return costCenterFacade.add(dto);
    }

    /**
     * 更新成本中心
     */
    @PostMapping("/update")
    public Boolean update(@RequestBody CostCenterDTO dto) {
        return this.costCenterFacade.update(dto);
    }

    /**
     * 删除成本中心
     */
    @PostMapping("/remove/{id}")
    public Boolean remove(@PathVariable Long id) {
        return this.costCenterFacade.remove(id);
    }

}

